//Name: Sara Thorup
#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"


/*
Unit tests for  int scoreFor(int player, struct gameState *state)
scoreFor() returns the the specified player's score based on curse, estate, duchy, province, great hall, and garndens

Things to test:
- When the player has no score influencing cards
- When the player only has curse score influencing cards (negative score)
- When player only has estate, dutchy, province, and great hall
- When the player has gardens but no other modifiying cars
- When player has a mix of scoring cards


*/
void test();
void setNonScoringCards(struct gameState* gameState, int testPlayer);

int main(int argc, char *argv[]) {
	printf("\n ===== Testing scoreFor() =====\n");
	test();
    return 0;
}

void test() {
	//setup
	struct gameState* gameState = newGame();
	int testPlayer = 0;
	int numPlayers = 2;
	int kingdomCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	int randomSeed = 10;

	//test when user has no score-influencing cards
	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	setNonScoringCards(gameState, testPlayer);
	

	int expectedScore = 0;
	if (expectedScore == scoreFor(testPlayer, gameState)) {
		printf("scoreFor(): PASS when player has no score-influencing cards \n");
	}
	else {
		printf("scoreFor(): FAIL when player has no score-influencing cards\n");
	}

	//test when user has negative score-influencing cards
	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	setNonScoringCards(gameState, testPlayer);
	gameState->hand[testPlayer][1] = curse;
	gameState->hand[testPlayer][0] = curse;
	gameState->deck[testPlayer][0] = curse;
	gameState->deck[testPlayer][4] = curse;
	gameState->discard[testPlayer][2] = curse;

	expectedScore = -5;
	if (expectedScore == scoreFor(testPlayer, gameState)) {
		printf("scoreFor(): PASS when player has curse cards but no other score-influencing cards \n");
	}
	else {
		printf("scoreFor(): FAIL when player has curse cards but no other score-influencing cards\n");
	}

	//test when user estate, duchy, province and great hall
	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	setNonScoringCards(gameState, testPlayer);
	gameState->hand[testPlayer][0] = estate;  //1
	gameState->hand[testPlayer][1] = duchy; //3
	gameState->hand[testPlayer][2] = great_hall; //1
	gameState->discard[testPlayer][0] = province; //6
	gameState->discard[testPlayer][1] = gold;
	gameState->discard[testPlayer][2] = duchy; //3
	gameState->discard[testPlayer][3] = province; //6
	gameState->deck[testPlayer][0] = duchy;  //3
	gameState->deck[testPlayer][1] = great_hall; //1
	gameState->deck[testPlayer][2] = gold;
	gameState->deck[testPlayer][3] = province; //6
	gameState->deck[testPlayer][4] = estate; //1
	

	expectedScore = 31;
	if (expectedScore == scoreFor(testPlayer, gameState)) {
		printf("scoreFor(): PASS when player has has duchy, province, estate, and great hall \n");
	}
	else {
		printf("scoreFor(): FAIL when player has has duchy, province, estate, and great hall\n");
	}

	//test when user has one garden card, and no score influrencing cards
	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	setNonScoringCards(gameState, testPlayer);
	gameState->hand[testPlayer][0] = gardens; 
	expectedScore = 1;  //garden gives 1 point for ever 10 cards.  player has 12 cards
	if (expectedScore == scoreFor(testPlayer, gameState)) {
		printf("scoreFor(): PASS when player has one garden card and no other score modifiers \n");
	}
	else {
		printf("scoreFor(): FAIL when player has one garden card and no other score modifiers\n");
	}

	//test when user has a mix of score cards
	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	setNonScoringCards(gameState, testPlayer);
	gameState->hand[testPlayer][0] = estate;  //1
	gameState->hand[testPlayer][1] = duchy; //3
	gameState->hand[testPlayer][2] = gardens; //1
	gameState->discard[testPlayer][0] = curse; //-1
	gameState->discard[testPlayer][1] = gold;
	gameState->discard[testPlayer][2] = duchy; //3
	gameState->discard[testPlayer][3] = curse; //-1
	gameState->deck[testPlayer][0] = gardens;  //1
	gameState->deck[testPlayer][1] = great_hall; //1
	gameState->deck[testPlayer][2] = gold;
	gameState->deck[testPlayer][3] = smithy; 
	gameState->deck[testPlayer][4] = estate; //1
	gameState->hand[testPlayer][0] = province; //6
	
	expectedScore = 15;  //garden gives 1 point for ever 10 cards.  player has 12 cards
	if (expectedScore == scoreFor(testPlayer, gameState)) {
		printf("scoreFor(): PASS when player has a mix of sore cards \n");
	}
	else {
		printf("scoreFor(): FAIL when player has a mix of score cards\n");
	}

}

void setNonScoringCards(struct gameState* gameState, int testPlayer) {
	gameState->handCount[testPlayer] = 3;
    gameState->discardCount[testPlayer] = 4;
    gameState->deckCount[testPlayer] = 5;

    int i = 0;
    for (; i < gameState->handCount[testPlayer]; i++) {
    	gameState->hand[testPlayer][i] = gold;
    }
   
   	for (i = 0; i < gameState->discardCount[testPlayer]; i++) {
   		gameState->discard[testPlayer][i] = gold;
   	}

   	for (i = 0; i < gameState->deckCount[testPlayer]; i++) {
   		gameState->deck[testPlayer][i] = gold;
   	}

}